<html>
	<head>
		<title>Sonna: search test</title>
		<script src="https://159.213.137.77/facebook/fxb_api/utils/utils.js" type="text/javascript"></script>
		<script src="https://159.213.137.77/facebook/fxb_api/request.js" type="text/javascript"></script>
		<script src="https://159.213.137.77/facebook/fxb_api/fXb_all.js" type="text/javascript"></script>
		
		<script type="text/javascript">
			function googleSearch(){
				if(!_fb_user.isLogged()){
					alert('Please login first');
					return;
				}
				
				var elem_text = document.getElementById('google_search');
				var text = escape(elem_text.value);
				window.open('http://www.google.it/#hl=it&output=search&q=' + text, '_blank');
				saveSearch(_fb_user.getUserId(), 'google', text);
			}
			
			function wikiSearch(){
				if(!_fb_user.isLogged()){
					alert('Please login first');
					return;
				}
					
				var elem_text = document.getElementById('wiki_search');
				var text = escape(elem_text.value);
				window.open('http://it.wikipedia.org/w/index.php?search=' + text, '_blank');
				saveSearch(_fb_user.getUserId(), 'wikipedia', text);				
			}
			
			function checkKey(event, name){
				if (event.keyCode == 13)
					document.getElementById(name + '_btn').click();
			}
			
			function tempSuccess(result){
				log('L\'utente è stato inserito correttamente nel db');	
			}
			
			function tempFailure(result){
				log('c\' stato qualche problema!');	
			}	
			
			function saveUserId(resp){
				var req = new Request();
				req.setOnSuccess(tempSuccess);
				req.setOnFailure(tempFailure);
				req.asyncPutRequest('../services/service.php/' + resp.userID);
			}
			
			function saveSearch(userId, engine, search){
				var req = new Request();
				req.setOnSuccess(tempSuccess);
				req.setOnFailure(tempFailure);
				req.asyncPutRequest('../services/service.php/' + userId + '/' + engine + '/' + search);
			}
		</script>
	</head>
	<body>
		<h3>Test salvataggio dati ricerche</h3>
		<div style="display: block">
			<div>
				<span>Search with google: </span>
				<input type="text" name="google_search" id="google_search" onkeydown="checkKey(event, this.id);"/>
				<input type="button" name="google_search_btn" id="google_search_btn" value="Search" onclick="googleSearch();"/>
			</div>
			
			<div>
				<span>Search with wikipedia: </span>
				<input type="text" name="wiki_search" id="wiki_search" onkeydown="checkKey(event, this.id);"/>
				<input type="button" name="wiki_search_btn" id="wiki_search_btn" value="Search" onclick="wikiSearch();"/>
			</div>
		</div>
		
		
		<div id="fb-root">
			
		</div>
		<!--input type="button" name="createXVRObj" value="createXVRObj" id="createXVRObj" onclick="createXVRObj();" /-->
		<input type="button" name="login" value="login" id="login" onclick="login(saveUserId);" />
		<input type="button" name="logout" value="logout" id="logout" onclick="logout();" />

	</body>
</html>